import 'scss/page-layout.scss'; // 公共标准布局样式
import 'static/css/index.scss';
import 'static/css/common.scss';
import Vue from 'vue';
// 导入路由模块
import Router from '../router/index';
import Store from '../store/index';
import { util, cacheUtil, post } from 'utils/util'; // 工具类
import { Date2String, Date2Week, isAuthorizedUrl } from 'utils/funcs';
import SysMsg from 'specials/sys-msg/sys-msg';
import BtUi from 'bontal-base-ui';
import 'bontal-base-ui/dist/bontal-base-ui.css';
import App from 'modules/index/index.vue';
import SubmitModal from '@/modules/index/src/components/submit-modal.vue';

Vue.use(BtUi);
Vue.component('SubmitModal', SubmitModal);
window.SubmitModal = SubmitModal;
window.Message = BtUi.Message;
window.MessageBox = BtUi.MessageBox;
// 菜单状态
const menuStatus = {
  hasLoadMenu: false,
  toPath: ''
};
// new Vue({
//   el: '#main-box',
//   store: newstore,
//   router: newrouter,
//   render: h => h(App)
// });
// 导航前置守卫拦截器
Router.beforeEach((to, from, next) => {
  // 对路由变化作出响应...
  if (!menuStatus.hasLoadMenu) {
    // 菜单未加载完成之前无需跳转
    menuStatus.toPath = to.path;
    return;
  } else if (to.path !== '/' && !isAuthorizedUrl(to.path)) {
    // 前端权限校验，
    // console.log('Permission denied. ' + to.path);
    // next(false);
    // return;
  }
  next();
});
/** ******  主页面逻辑  ********/
new Vue({
  el: '#main-box',
  store: Store,
  router: Router,

  components: {
    // MainHeader:BtUi.MainHeader,
    // MainNav:BtUi.MainNav,
    SysMsg: SysMsg
  },
  data() {
    return {
      check: true,
      fullscreenLoading: false,
      oper: {
        c_oper_name: '',
        c_oper_code: '',
        c_login_dept_code: '',
        c_login_dept_name: '',
        c_oper_depts: []
      },
      nowdate: '',
      menusData: []
    };
  },
  created() {
    // `this` 指向 vm 实例
    const date = new Date();
    this.nowdate = Date2String(date, 'yyyy-MM-dd') + ' ' + Date2Week(date);
    this.oper = util.getOper();
    // 将后台返回菜单中的url替换为componentName
    util.getUsermenu(menus => {
      const menusData = menus.filter(t => {
        return t.code === '140';
      });
      window.userMenus = menusData[0].subMenu || [];
      this.menusData = window.userMenus || [];
      menuStatus.hasLoadMenu = true;
      // 路由跳转
      if (menuStatus.toPath) {
        this.$router.push({
          path: menuStatus.toPath
        });
      }
    });
  },
  methods: {
    editPassWD(e) {
      console.log('修改密码');
    },
    logoutsys(e) {
      const logoutUrl = SERVICE_URL + '/auth/logout';
      post(logoutUrl, {
        'data': cacheUtil.getSessionOper()
      }, resp => {
        cacheUtil.clearCookie();
        window.location.href = './login.html';
      }, () => {
        cacheUtil.clearCookie();
        window.location.href = './login.html';
      }
      );
    },
    clickUser(e) {
      console.log('点击用户名');
    }
  },
  render: h => h(App)
});
